package com.workflow.service.impl;


import com.flowable.FlowProcDefDto;
import com.workflow.dao.FlowDeployMapper;
import com.workflow.service.IFlowDefinitionService;
import lombok.extern.slf4j.Slf4j;
import org.flowable.engine.RepositoryService;
import org.flowable.engine.repository.ProcessDefinitionQuery;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;


/**
 * 流程定义
 *
 * @author Tony
 * @date 2021-04-03
 */
@Service
@Slf4j
public class FlowDefinitionServiceImpl implements IFlowDefinitionService {

    @Resource
    private FlowDeployMapper flowDeployMapper;

    @Resource
    protected RepositoryService repositoryService;



    @Override
    public boolean exist(String processDefinitionKey) {
        ProcessDefinitionQuery processDefinitionQuery
                = repositoryService.createProcessDefinitionQuery().processDefinitionKey(processDefinitionKey);
        long count = processDefinitionQuery.count();
        return count > 0 ? true : false;
    }

    /**
     * 流程定义列表
     * @return 流程定义分页列表数据
     */
    @Override
    public List<FlowProcDefDto> list(String name) {
        final List<FlowProcDefDto> dataList = flowDeployMapper.selectDeployList(name);
        return dataList;
    }




}
